package com.atguigu.pa;

import com.atguigu.ds.impl.DynamicArrayStack;

import java.util.Scanner;

public class L20 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        do {
            DynamicArrayStack<Character> stack = new DynamicArrayStack<>();
            System.out.print("请输入:");
            String str = input.nextLine();
            for(int i = 0 ; i<str.length() ; i++){
                char c = str.charAt(i);
                if(c=='(' || c=='[' || c=='{'){
                    stack.push(c);
                }else{
                    //  ()]]
                    if(stack.isEmpty()){
                        System.out.println("false");
                        break;
                    }
                    char c2 = stack.pop();
                    if(!((c==')' && c2=='(') || (c==']' && c2=='[') || (c=='}' && c2== '{'))){
                        System.out.println("false");
                        break;
                    }
                }
            }

            //  (([]
            if(stack.isEmpty()){
                System.out.println("true");
            }

            System.out.print("输入Y继续：");
        }while ("y".equalsIgnoreCase(input.nextLine()));
    }
}
